package com.ywk.mybatisPlus.business.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ywk.mybatisPlus.business.entity.Student;
import com.ywk.mybatisPlus.business.mapper.StudentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author zbh
 * @Date 2023/6/28
 */
@Service
public class StudentService {

    @Autowired
    StudentMapper mapper;

    public List<Student> findAll(){
        ////SELECT * FROM tb_student
        List<Student> students = mapper.selectList(null);
        return students;
    }

    public List<Student> select(){
        ////SELECT * FROM tb_student WHERE is_deleted=0 AND (profession LIKE ? AND age BETWEEN ? AND ? AND email IS NOT NULL)
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper
                .like("profession", "软件")
                .between("age",18,24)
                .isNotNull("email");
        List<Student> students = mapper.selectList(queryWrapper);
        return students;
    }

    public Page<Student> findPage(){
        ////SELECT * FROM tb_student
        Page<Student> page = new Page<>(1, 5);
        mapper.selectPage(page,null);
        return page;
    }
}
